﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends Admin_Controller {
    function Admin(){
        parent::Admin_Controller();
        $this->load->model('news_model');
        $this->load->model('admin_model');
        $this->load->library('session');
        $this->load->helper('url');
        $this->bep_assets->load_asset('master');
    }
    public function index()
    {
        $this->article_list();
    }

    public function article_list($pages=0)
    {
        //TODO $text=substr ("$text", 0,strpos ($text, " ", 300)); обрезать текст и добавлять"подробнее"
        $pages = $pages!=0?$pages*5 -5: $pages;
        $data['module'] ='news';
        $data['article_list'] = $this->admin_model->get_article_list($pages);
        $data['page'] = $this->config->item('backendpro_template_admin') . "articlelist";

        $this->load->view($this->_container,$data);
    }

    public function article($id)
    {
        $data['article'] = $this->news_model->get_article_by_id($id);
        $data['module'] ='news';
        $data['page'] = $this->config->item('backendpro_template_admin') . "article";
        $this->load->view($this->_container,$data);
    }

    private function _generate_pagination()
    {
        $article_to_page = 5;
        $count_rows = $this->admin_model->_get_content_count_rows();
        $data['pages_count'] = ceil($count_rows/$article_to_page);
        $data['page'] = $this->config->item('backendpro_template_admin') . "pagination";
        $data['module'] ='news';
        $this->load->view($this->_container,$data);
    }
}

